package com.yax.mickey.controller;

import com.yax.mickey.common.result.Result;
import com.yax.mickey.entity.Category;
import com.yax.mickey.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@ResponseBody
@RestController
@RequestMapping("/category")
@Api(tags = "用户端商品分类信息相关接口")
@Slf4j
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @GetMapping("/getAllCategories")
    @ApiOperation("获取所有商品分类信息")
    public Result<List<Category>> getAllCategories() {
        List<Category> categoryList = categoryService.getAllCategories();
        return Result.success(categoryList);
    }

    @GetMapping("/getCategoryById/{categoryId}")
    @ApiOperation("根据分类ID查询分类")
    public Result<Category> getCategoryByCategoryId(@PathVariable Integer categoryId) {
        Category category = categoryService.getCategoryByCategoryId(categoryId);
        return Result.success(category);
    }

    @GetMapping("/getCategoryByName/{categoryName}")
    @ApiOperation("根据分类名称查询")
    public Result<Category> getCategoryByCategoryName(@PathVariable String categoryName) {
        Category category = categoryService.getCategoryByCategoryName(categoryName);
        return Result.success(category);
    }

}
